package com.recycle.system.domain.dto;

import com.recycle.common.core.domain.BaseEntity;
import com.recycle.common.enums.Recyclable;
import com.recycle.system.domain.WasteResource;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author sorakado
 * 订单新增DTO
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class NewOrder extends BaseEntity {

    private Long orderId;
    private Long publisherId;
    private Long finisherId;
    private String description;

    private BigDecimal paper;
    private BigDecimal plastic;
    private BigDecimal glass;
    private BigDecimal metal;
    private BigDecimal cloth;
    private BigDecimal paperPrice;
    private BigDecimal plasticPrice;
    private BigDecimal glassPrice;
    private BigDecimal metalPrice;
    private BigDecimal clothPrice;

    private List<WasteResource> resources = new ArrayList<>();


    public void mergeResource(){
        if(paper != null && paperPrice != null){
            WasteResource build = WasteResource.builder().resourceTypeId(Recyclable.PAPER.getValue()).resourceType(Recyclable.PAPER.getLabel())
                    .weight(paper).price(paperPrice).build();
            resources.add(build);
        } if(plastic != null && plasticPrice != null){
            WasteResource build = WasteResource.builder().resourceTypeId(Recyclable.PLASTIC.getValue()).resourceType(Recyclable.PLASTIC.getLabel())
                    .weight(plastic).price(plasticPrice).build();
            resources.add(build);
        }
        if(glass != null && glassPrice != null){
            WasteResource build = WasteResource.builder().resourceTypeId(Recyclable.GLASS.getValue()).resourceType(Recyclable.GLASS.getLabel())
                    .weight(glass).price(glassPrice).build();
            resources.add(build);
        }
        if(metal != null && metalPrice != null){
            WasteResource build = WasteResource.builder().resourceTypeId(Recyclable.METAL.getValue()).resourceType(Recyclable.METAL.getLabel())
                    .weight(metal).price(metalPrice).build();
            resources.add(build);
        }
        if(cloth != null && clothPrice != null){
            WasteResource build = WasteResource.builder().resourceTypeId(Recyclable.CLOTH.getValue()).resourceType(Recyclable.CLOTH.getLabel())
                    .weight(cloth).price(clothPrice).build();
            resources.add(build);
        }
    }
}

